package com.baseweb.webadmin.service.impl;


import com.baseweb.webadmin.core.model.dao.AccountDao;
import com.baseweb.webadmin.core.model.dao.ByCoinsLogDao;
import com.baseweb.webadmin.core.model.dao.ByMoneyLogDao;
import com.baseweb.webadmin.core.model.mapper.ByCoinsLogMapper;
import com.baseweb.webadmin.core.model.mapper.ByMoneyLogMapper;
import com.baseweb.webadmin.core.model.mapper.ByUserVoucherMapper;
import com.baseweb.webadmin.core.model.pojo.*;
import com.baseweb.webadmin.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private ByMoneyLogDao byMoneyLogDao;
    @Autowired
    private ByCoinsLogDao byCoinsLogDao;

    @Autowired
    private AccountDao accountDao;

    @Autowired
    private ByCoinsLogMapper byCoinsLogMapper;

    @Autowired
    private ByMoneyLogMapper byMoneyLogMapper;

    @Override
    public List<ByCoinsLog> selectCoinsLogListByPage(Integer userId, Integer start, Integer offset) {
        return byCoinsLogDao.selectListByPage(userId, start, offset);
    }

    @Override
    public Integer selectCoinsLogListCount(Integer userId) {
        return byCoinsLogDao.selectListCount(userId);
    }

    @Override
    public List<ByMoneyLog> selectMoneyLogListByPage(Integer userId, Integer start, Integer offset) {
        return byMoneyLogDao.selectListByPage(userId, start, offset);
    }

    @Override
    public Integer selectMoneyLogListCount(Integer userId) {
        return byMoneyLogDao.selectListCount(userId);
    }

    @Override
    public int insertCoinsLog(ByCoinsLog byCoinsLog) {
        return byCoinsLogMapper.insert(byCoinsLog);
    }

    @Override
    public int insertMoneyLog(ByMoneyLog byMoneyLog) {
        return byMoneyLogMapper.insert(byMoneyLog);
    }

    @Override
    public Integer insertVoucher(ByUserVoucher byUserVoucher) {
        return accountDao.insertVoucher(byUserVoucher);
    }

    @Override
    public ByUserVoucher findVoucher(Integer id) {
        return accountDao.findVoucher(id);
    }

    @Override
    public List<ByUserVoucher> selectVoucherListByPage(Integer userId, Integer start, Integer offset) {
        return accountDao.selectVoucherListByPage(userId, start, offset);
    }

    @Override
    public Integer selectVoucherListCount(Integer userId) {
        return accountDao.selectVoucherListCount(userId);
    }

    @Override
    public Integer insertWithdrawAccount(ByUserWithdrawAccount byUserWithdrawAccount) {
        return accountDao.insertWithdrawAccount(byUserWithdrawAccount);
    }

    @Override
    public ByUserWithdrawAccount findWithdrawAccount(Integer id) {
        return accountDao.findWithdrawAccount(id);
    }

    @Override
    public List<ByUserWithdrawAccount> selectWithdrawAccountListByPage(Integer userId, Integer start, Integer offset) {
        return accountDao.selectWithdrawAccountListByPage(userId, start, offset);
    }

    @Override
    public Integer selectWithdrawAccountListCount(Integer userId) {
        return accountDao.selectWithdrawAccountListCount(userId);
    }

    @Override
    public Integer insertWithdraw(ByUserWithdraw byUserWithdraw) {
        return accountDao.insertWithdraw(byUserWithdraw);
    }

    @Override
    public ByUserWithdraw findWithdraw(Integer id) {
        return accountDao.findWithdraw(id);
    }

    @Override
    public List<ByUserWithdraw> selectWithdrawListByPage(Integer userId, Integer start, Integer offset) {
        if(userId != null && userId > 0){
            List<Integer> userIds = new ArrayList<Integer>();
            userIds.add(userId);
            return accountDao.selectWithdrawListByPage(userIds, start, offset);
        }
        return accountDao.selectWithdrawListByPage(null, start, offset);
    }

    @Override
    public Integer selectWithdrawListCount(Integer userId) {
        if(userId != null && userId > 0){
            List<Integer> userIds = new ArrayList<Integer>();
            userIds.add(userId);
            return accountDao.selectWithdrawListCount(userIds);
        }
        return accountDao.selectWithdrawListCount(null);
    }

    @Override
    public List<ByUserWithdraw> selectWithdrawListByIdsPage(List<Integer> userIds, Integer start, Integer offset) {
        return accountDao.selectWithdrawListByPage(userIds, start, offset);
    }

    @Override
    public Integer selectWithdrawListIdsCount(List<Integer> userIds) {
        return accountDao.selectWithdrawListCount(userIds);
    }
}
